package sketch.generator.experiment;

import sketch.generator.Generator;
import sketch.generator.IGenerator;
import sketch.util.SketchUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class VariousValueGroupGeneratorTest extends TestCase {

	public static Test suite() {
		return new TestSuite(VariousValueGroupGeneratorTest.class);
	}
	
	public void testChainValueGroupGenerator() {
		ValueGroupGenerator<Integer> generator = new ChainValueGroupGenerator<Integer>(1, 2, 3);
		
		assertTrue(generator.hasNext());
		assertEquals("[1]", generator.next().toString());
		
		assertTrue(generator.hasNext());
		assertEquals("[2]", generator.next().toString());
		
		assertTrue(generator.hasNext());
		assertEquals("[3]", generator.next().toString());
		
		assertTrue(!generator.hasNext());
		
		generator.reset();
		
		assertTrue(generator.hasNext());
		assertEquals("[1]", generator.next().toString());
		
		assertTrue(generator.hasNext());
		assertEquals("[2]", generator.next().toString());
		
		assertTrue(generator.hasNext());
		assertEquals("[3]", generator.next().toString());
		
		assertTrue(!generator.hasNext());
	}
	
    public void testExhaustiveValueGroupGenerator() {
    	ValueGroupGenerator<Integer> generator = new ExhaustiveValueGroupGenerator<Integer>(1, 2, 3, 4);
    	for(int i = 0; i < 4*4*4*4 + 4*4*4 + 4*4 + 4; i++) {
    		assertTrue(generator.hasNext());
    		generator.next();
    	}
    	assertTrue(!generator.hasNext());
    	
    	generator.reset();
    	
    	for(int i = 0; i < 4*4*4*4 + 4*4*4 + 4*4 + 4; i++) {
    		assertTrue(generator.hasNext());
    		generator.next();
    	}
    	assertTrue(!generator.hasNext());
    	SketchUtil.stdln("-----------");
	}
    
    public void testNondetValueGroupGenerator() {
    	ValueGroupGenerator<Integer> generator = new NondetValueGroupGenerator<Integer>(1, 2, 3, 4);
    	for(int i = 0; i < 4; i++) {
    		assertTrue(generator.hasNext());
    		SketchUtil.stdln(generator.next());
    	}
    	assertTrue(!generator.hasNext());
    	SketchUtil.stdln("-----------");
	}
    
    public void testRandomValueGroupGenerator() {
    	ValueGroupGenerator<Integer> generator = new RandomValueGroupGenerator<Integer>(1, 2, 3, 4);
    	//for(int i = 0; i < 3; i++) {
    		assertTrue(generator.hasNext());
    		SketchUtil.stdln(generator.next());
    		
    		assertTrue(!generator.hasNext());
    		
    		generator.reset();
    		assertTrue(generator.hasNext());
    		SketchUtil.stdln(generator.next());
    		
    		generator.reset();
    		assertTrue(generator.hasNext());
    		SketchUtil.stdln(generator.next());
    	//}
    	//assertTrue(!generator.hasNext());
    }
    
    public void testSubsetValueGroupGenerator() {
    	ValueGroupGenerator<Integer> generator = new SubsetValueGroupGenerator<Integer>(1, 2, 3, 4);
    	for(int i = 0; i < 16; i++) {
    		assertTrue(generator.hasNext());
    		generator.next();
    	}
    	assertTrue(!generator.hasNext());
    	
    	generator.reset();
    	
    	for(int i = 0; i < 16; i++) {
    		assertTrue(generator.hasNext());
    		generator.next();
    	}
    	assertTrue(!generator.hasNext());
    }
    
    public void testSingleValueGroupGenerator() {
    	SingleValueGroupGenerator<Integer> g = new SingleValueGroupGenerator<Integer>(1);
    	assertTrue(g.hasNext());
    	ValueGroup<Integer> next = g.next();
    	assertEquals("[1]", next.toString());
    	assertTrue(!g.hasNext());
    	
    	g.reset();
    	
    	assertTrue(g.hasNext());
        next = g.next();
    	assertEquals("[1]", next.toString());
    	assertTrue(!g.hasNext());
    }
}